<?php
namespace app\common\logic;
use app\common\model\CustomerServiceModel;
use app\common\model\ShopModel;

class KefuLogic{
    public static function getKefu($shop_id)
    {
        if(null !== $shop = ShopModel::find($shop_id)){
            if($shop->kefu){
                $kefu=[
                    'name'=>$shop->kefu->name,
                    'qrcode'=>$shop->kefu->qrcode,
                    'mobile'=>$shop->kefu->mobile,
                ];
            }
        }
//        dump($shop);die;
        if(!isset($kefu)){
            $kefus=CustomerServiceModel::where(['is_delete'=>0,'is_default'=>1])->select()->toArray();
            if(!empty($kefus)){
                $kefu = $kefus[array_rand($kefus,1)] ?? [];
            }
        }

        if(!isset($kefu) || empty($kefu)){
            $kefu=[
                'name'=>'Mr.Zhang',
                'qrcode'=>null,
                'mobile'=>'13840374116',
            ];
        }

        return $kefu;
    }
}
